package cn.lookup.mapper;

import cn.lookup.domain.Account;
import cn.lookup.domain.Order;
import cn.lookup.handler.DateHandler;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface AccountMapper {
    @Select("select * from account")
    @Results({
            @Result(column = "id",property = "id",id = true),
            @Result(column = "name",property = "name"),
            @Result(column = "money",property = "money"),
            @Result(column = "birthday",property = "birthday",typeHandler = DateHandler.class)
    })
    public List<Account> findAll();
    @Delete("delete from account where id = #{id}")
    public void deleteAccount(int id);
    @Select("select * from account where id = #{id}")
    @Results({
            @Result(column = "id",property = "id",id = true),
            @Result(column = "name",property = "name"),
            @Result(column = "money",property = "money"),
            @Result(column = "birthday",property = "birthday",typeHandler = DateHandler.class)
    })
    public Account queryAccountById(int id);
    @Select("select * from account where id = #{id}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(column = "money",property = "money"),
            @Result(column = "birthday",property = "birthday",typeHandler = DateHandler.class),
            @Result(javaType = List.class,property = "orderList",column = "id",many = @Many(select = "cn.lookup.mapper.OrderMapper.queryAllOrderByUid"))
    })
    public Account queryAccountAndOrders(int id);
    @Select("select * from account where id = #{id}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(column = "money",property = "money"),
            @Result(column = "birthday",property = "birthday",typeHandler = DateHandler.class),
            @Result(javaType = List.class,property = "roleList",column = "id",many = @Many(select = "cn.lookup.mapper.RoleMapper.queryRolesByUid"))
    })
    public Account queryAccountAndRoles(int id);
}
